/**
 * push() 方法将指定的元素添加到数组的末尾，并返回新的数组长度。
 *
 *注： 这里巧妙利用数组长度变化来实现
 * @param  {...any} rest,可以是一个值或者多个用逗号隔开的值
 * @returns 数组长度
 */
Array.prototype.myPush = function (...rest) {
  if (!Array.isArray(this)) throw new TypeError("musted be called by array");

  let _temp = [...rest];

  for (let i = 0; i < _temp.length; i++) {
    this[this.length] = _temp[i];
  }
  return this.length;
};

// egg
let arr = [1, 2, 3, 4];
console.log("[ arr ] >", arr.myPush());
console.log("[ arr1 ] >", arr.myPush(1));
console.log("[ arr1 ] >", arr.myPush(1, 2));

let arr1 = [1, 2, 3, 4];
console.log("[ arr ] >", arr1.push());
console.log("[ arr11 ] >", arr1.push(1));
console.log("[ arr11 ] >", arr1.push(1, 2));
